﻿// --------------------------------
// <copyright file="BackgroundLayerAnimation.cs" company="Faculty of Information Technology, Czech Technical University in Prague">
//     This document is shared by Microsoft Public License (MS-PL)
//     For further details please see http://msdn.microsoft.com/en-us/library/ff648068.aspx or license.txt.
// </copyright>
// <author>Lukáš Molnár</author>

// <email>molnaluk@fit.cvut.cz</email>

// <date>9. 11. 2011 22:22:37</date>

// <summary>
//
// </summary>
// --------------------------------

using System.Collections.Generic;
using System.Xml.Serialization;
using FITClub.Util;
using Microsoft.Xna.Framework;

namespace FITClub.TextureMenu
{
    public class BackgroundLayerAnimated : BackgroundLayer
    {
        [XmlArray]
        [XmlArrayItem(ElementName = "Delta")]
        public List<Point> Motion { get; set; }

        [XmlIgnore]
        private int frame = 0;

        public BackgroundLayerAnimated()
        {
        }

        private Point GetDelta()
        {
            if (frame == Motion.Count)
            {
                frame = 0;
            }
            return Motion[frame++];
        }

        public override void Update(Microsoft.Xna.Framework.GameTime gt)
        {
            if (MenuManager.Current.IsMoving)
            {
                base.Update(gt);
            }
            else
            {
                Point d = GetDelta();
                Bounds = Bounds.OffsetXY(d.X, d.Y);
            }
        }
    }
}